<?php

namespace App\Http\Models;

use Illuminate\Support\Facades\Redis;

class CacheModel
{
    const EXPIRE = 86400; // 86400

    // add cache
    public static function set($key, $str, $expire = 0) {
        $redis = Redis::connection('db_cache');
        if($expire == 0) $expire = self::EXPIRE;
        return $redis->setex($key, $expire, $str);
    }

    // get cache
    public static function get($key)
    {
        $redis = Redis::connection('db_cache_slave');
        return $redis->get($key);
    }

    // delete cache
    public static function del($key)
    {
        $redis = Redis::connection('db_cache');
        return $redis->del($key);
    }
}
